package com.woniuxy.controller;

import com.woniuxy.entity.Menu;
import com.woniuxy.entity.ResponseEntity;
import com.woniuxy.service.MenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 星星
 */
@RestController
@RequestMapping("menu")
@CrossOrigin
@Api(value = "菜单接口",description = "对菜单表进行CRUD")
public class MenuController {
    @Resource
    MenuService menuService;

    /**
     * Description : 根据管理员权限查询左侧菜单
     * ChangeLog : 1. 创建 (2021/5/15 14:23 [zjx]);
     * @param id 角色id
     * @return 集合
    */
    @ApiOperation("根据管理员权限查询左侧菜单")
    @GetMapping("/findLefMenu/{id}")
    public ResponseEntity findLeftMenu(@ApiParam("角色id") @PathVariable int id){
        List<Menu> menuList = this.menuService.findLeftMenu(id);
        return new ResponseEntity(200,"根据管理员权限查询左侧菜单成功",menuList);

    }

    /**
     * Description : 多级菜单查询
     * ChangeLog : 1. 创建 (2021/5/15 14:23 [zjx]);
     *
     * @return 列表
    */
    @ApiOperation("多级菜单查询")
    @GetMapping("selectMenus")
    public ResponseEntity selectMenus() {
        List<Menu> menuList = menuService.selectMenus();
        return new ResponseEntity(200,"多级菜单查询成功",menuList);
    }

    /**
     * Description : 查询所有菜单
     * ChangeLog : 1. 创建 (2021/5/15 14:24 [zjx]);
     *
     * @return null
    */
    @GetMapping("selectAll")
    @ApiOperation("查询所有菜单")
    public ResponseEntity selectAll(){
        List<Menu> menuList = menuService.selectAll();
        return new ResponseEntity(200,"查询所有菜单成功",menuList);
    }

    /**
     * Description : 插入一条数据
     * ChangeLog : 1. 创建 (2021/5/15 14:24 [zjx]);
     * @param menu 菜单实体
     * @return 字符串
    */
    @PostMapping("insertOne")
    @ApiOperation("插入一条数据")
    public ResponseEntity insertOne(@RequestBody Menu menu){
        String result = this.menuService.insertOne(menu);
        return new ResponseEntity(200, result, null);
    }

    /**
     * Description : 根据id查询菜单
     * ChangeLog : 1. 创建 (2021/5/15 14:25 [zjx]);
     * @param id 菜单id
     * @return 菜单
    */
    @GetMapping("selectOne/{id}")
    @ApiOperation("根据id查询菜单")
    public ResponseEntity selectOne(@PathVariable(value = "id") int id){
        Menu menu = menuService.selectOne(id);
        return new ResponseEntity(200, "根据id查询菜单成功", menu);
    }

    /**
     * Description : 修改一条菜单信息
     * ChangeLog : 1. 创建 (2021/5/15 14:25 [zjx]);
     * @param menu 菜单实体
     * @return null
    */
    @PostMapping("updateOne")
    @ApiOperation("修改一条菜单信息")
    public ResponseEntity updateOne(@RequestBody Menu menu){
        String result = this.menuService.updateOne(menu);
        return new ResponseEntity(200, result, null);
        }

    /**
     * Description : 根据id删除一条数据
     * ChangeLog : 1. 创建 (2021/5/15 14:26 [zjx]);
     * @param id 菜单id
     * @return null
    */
    @GetMapping("deleteOne/{id}")
    @ApiOperation("删除一条菜单信息")
    public ResponseEntity deleteOne(@ApiParam("菜单id")@PathVariable(value = "id") int id){
        String result = this.menuService.deleteOne(id);
        return new ResponseEntity(200, result, null);
    }
}
